package com.devops.admin.graphql;

import com.devops.admin.model.DOSKubernetesYamlRelation;
import com.devops.admin.model.TableResult;
import com.devops.admin.po.DOSKubernetesResourcePo;
import com.devops.admin.service.DOSKubernetesResourceService;
import com.devops.admin.vo.DOSKubernetesResourceVo;
import com.devops.admin.vo.DOSPageVo;
import com.devops.common.annotation.DOSLog;
import com.devops.common.utils.Message;
import com.devops.constant.DevOpsConstant;
import com.netflix.graphql.dgs.DgsComponent;
import com.netflix.graphql.dgs.DgsMutation;
import com.netflix.graphql.dgs.DgsQuery;
import com.netflix.graphql.dgs.InputArgument;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @ClassName DOSKubernetesResourceDataFetcher
 * @Description TODO
 * @Author heyabo
 * @Date 2022/8/15 16:57
 * @Version 1.0
 **/
@DgsComponent
public class DOSKubernetesResourceDataFetcher {

    @Autowired
    private DOSKubernetesResourceService dosKubernetesResourceService;

    /**
     * @Author heyabo
     * @Description 部署项目 - 通过yaml文件部署
     * @Date 14:35 2022/8/11
     * @Param [kubernetesResource]
     * @return com.devops.common.utils.Message
     **/
    @DgsMutation
    @DOSLog(description = "部署项目 - 通过yaml文件部署")
    @RequiresPermissions(DevOpsConstant.RoleCode.LOGIN_USER)
    public Message applyProject(@InputArgument DOSKubernetesResourceVo kubernetesResource){

        return dosKubernetesResourceService.applyProject(kubernetesResource);
    }

    /**
     * @Author heyabo
     * @Description 升级项目 - 通过yaml文件
     * @Date 16:34 2022/8/11
     * @Param [kubernetesResource]
     * @return com.devops.common.utils.Message
     **/
    @DgsMutation
    @DOSLog(description = "升级项目 - 通过yaml文件")
    @RequiresPermissions(DevOpsConstant.RoleCode.LOGIN_USER)
    public Message upgradeProject(@InputArgument DOSKubernetesResourceVo kubernetesResource){

        return dosKubernetesResourceService.upgradeProject(kubernetesResource);
    }

    /**
     * @Author heyabo
     * @Description 卸载项目 - 通过yaml文件
     * @Date 17:22 2022/8/11
     * @Param [kubernetesResource]
     * @return com.devops.common.utils.Message
     **/
    @DgsMutation
    @DOSLog(description = "卸载项目 - 通过yaml文件")
    @RequiresPermissions(DevOpsConstant.RoleCode.LOGIN_USER)
    public Message removeProject(@InputArgument Integer kubernetesResourceId){

        return dosKubernetesResourceService.removeProject(kubernetesResourceId);
    }

    /**
     * @Author heyabo
     * @Description 查询k8s资源列表
     * @Date 17:42 2022/8/11
     * @Param [kubernetesResource]
     * @return java.util.List<com.devops.admin.model.DOSKubernetesResource>
     **/
    @DgsQuery
    @DOSLog(description = "查询k8s资源列表")
    @RequiresPermissions(DevOpsConstant.RoleCode.LOGIN_USER)
    public List<DOSKubernetesResourcePo> getKubernetesResources(@InputArgument DOSKubernetesResourceVo kubernetesResource){

        return dosKubernetesResourceService.getList(kubernetesResource);
    }

    /**
     * @Author heyabo
     * @Description 分页查询k8s资源列表
     * @Date 09:34 2022/8/14
     * @Param [kubernetesResource]
     * @return com.devops.admin.model.TableResult<com.devops.admin.po.DOSKubernetesResourcePo>
     **/
    @DgsQuery
    @DOSLog(description = "分页查询k8s资源列表")
    @RequiresPermissions(DevOpsConstant.RoleCode.LOGIN_USER)
    public TableResult<DOSKubernetesResourcePo> getPageList(@InputArgument DOSKubernetesResourceVo kubernetesResource,@InputArgument DOSPageVo pageVo){

        return dosKubernetesResourceService.getPageList(kubernetesResource, pageVo);
    }

    /**
     * @Author heyabo
     * @Description 查询历史yaml文件
     * @Date 11:05 2022/8/16
     * @Param [kubernetesResourceId]
     * @return java.util.List<com.devops.admin.model.DOSKubernetesYamlRelation>
     **/
    @DgsQuery
    @DOSLog(description = "查询历史yaml文件")
    @RequiresPermissions(DevOpsConstant.RoleCode.LOGIN_USER)
    public List<DOSKubernetesYamlRelation> getYamlHistory(@InputArgument Integer kubernetesResourceId){

        return dosKubernetesResourceService.getHistorys(kubernetesResourceId);
    }
}
